//
//  YUIconView.m
//  QQZone
//
//  Created by 张洪毓 on 15/11/25.
//  Copyright © 2015年 张洪毓. All rights reserved.
//

#import "YUIconView.h"

@implementation YUIconView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
        [self setTitle:@"呵呵呵" forState:UIControlStateNormal];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    
    if (self.height > self.width) {
        return CGRectMake(0, self.width, self.width, kLabelNameH);
    }else {
        return CGRectZero;
    }
}

-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    if (self.height > self.width) {
        return CGRectMake(0, 0, self.width, self.width);
    }else {
        return self.bounds;
    }
}

-(void)setIsLandscape:(BOOL)isLandscape{
    
    if (isLandscape) {
        CGFloat X = self.superview.width * 0.33;
        CGFloat Y = 80;
        CGFloat W = X;
        CGFloat H = W + kLabelNameH;
        self.frame = CGRectMake(X, Y, W, H);
    }else {
        CGFloat X = 5;
        CGFloat Y = 20;
        CGFloat W = self.superview.width - 2 * X;
        CGFloat H = W;
        self.frame = CGRectMake(X, Y, W, H);
    }
}



@end
